package com.jzo2o.orders.manager.Handler.OrdersHandler;

import com.jzo2o.orders.base.model.domain.Orders;
import com.jzo2o.orders.manager.model.dto.request.PlaceOrderReqDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 用户下单参数校验handler
 */
@Slf4j
@Component
@Order(10)  // 第一个执行
public class OrderCheckHandlerNew extends OrdersHandlerNew {
    
    @Override
    public void process(Orders order, PlaceOrderReqDTO reqDTO) {
        log.info("用户下单参数校验handler");
        if (reqDTO.getServeId() == null) {
            throw new RuntimeException("服务id不能为空");
        }
        if (reqDTO.getAddressBookId() == null) {
            throw new RuntimeException("地址id不能为空");
        }
        if (reqDTO.getServeStartTime() == null) {
            throw new RuntimeException("预约时间不能为空");
        }
        if (reqDTO.getPurNum() == null) {
            throw new RuntimeException("购买数量不能为空");
        }
        if (reqDTO.getPurNum() <= 0) {
            throw new RuntimeException("购买数量不能小于0");
        }
    }
    
    @Override
    public int getOrder() {
        return 10;
    }
}